package com.no1ikun.util;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

public class NuUtil {
    public static void main(String[] args) {
        System.out.println(getNumber(1)+"结果");
    }
    //处理number自动增长问题
    public static String  getNumber(int cno){
        String selSql = "select top 1 sno from Student where sno like '%S2023"+cno+"%' order by sno desc";
        System.out.println(selSql);
        String year = new SimpleDateFormat("yyyy").format(new Date());

        ResultSet rs = JDBCUtil.executeQuery(selSql);
        String newNumber="S"+year+""+cno+"01";
        try {
            if (rs.next()) {
                //学号构成 年+系编号+班级号+学号
                //获取number
                String number = rs.getString("sno").trim();
                //班级号 应该是枚举类型
                String Cno="";
                String Dept="";

                System.out.println("nihao"+number);
                String substring = number.substring(number.length()-2);
                int i=Integer.parseInt(substring)+1;
                System.out.println(substring+"--"+i+"学号，数字");
                System.out.println(i);

                System.out.println("nihao"+year);


                newNumber=("S"+year)+cno+((i+"").length()>=2?i:"0"+i);
                System.out.println(newNumber);

            }

        } catch (Exception e) {

        }
        return newNumber;

    }
}
